#include <stdio.h>
#include <stdlib.h>

struct ListNode
{
	struct ListNode* next;
	int val;
};

//struct ListNode* removeElements(struct ListNode* head, int val) 
//{
//	struct ListNode* low = NULL;
//	struct ListNode* fact = head;
//	while (fact)
//	{
//		if (fact->val == val)
//		{
//			struct ListNode* next = fact->next;
//			free(fact);
//			if (low)
//				low->next = next;
//			fact = next;
//		}
//		else
//		{
//			low = fact;
//			fact = fact->next;
//		}
//
//	}
//	return head;
//}

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k)
{
	struct ListNode* low = pListHead;
	struct ListNode* fast = pListHead;
	while (fast->next)
	{
		int tmp = k;
		while (tmp && fast->next)
		{
			fast = fast->next;
			tmp--;
		}

		low = low->next;
	}
	return low;
}
int main()
{
	struct ListNode* n1 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n2 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n3 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n4 = (struct ListNode*)malloc(sizeof(struct ListNode));
	struct ListNode* n5 = (struct ListNode*)malloc(sizeof(struct ListNode));
	n1->val = 1;
	n2->val = 2;
	n3->val = 3;
	n4->val = 4;
	n5->val = 5;

	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next = n5;
	n5->next = NULL;
	struct ListNode* ret=FindKthToTail(n1, 1);
	printf("%d", ret->val);
	return 0;
}